package com.tungse.dynamic.cfg;

/**
 * @Author : Tungse
 * @Date: 2025/9/1 15:07
 * @Description:
 */
public class DataSourceContextHolder {
    private static final ThreadLocal<DataSourceType> contextHolder = new ThreadLocal<>();

    public static void setDataSourceType(DataSourceType type) {
        contextHolder.set(type);
    }

    public static DataSourceType getDataSourceType() {
        return contextHolder.get() == null ? DataSourceType.MASTER : contextHolder.get(); // 默认主库
    }
    public static void clear() {
        contextHolder.remove();
    }
}